#!/bin/bash
read -p "请输入外网Ip:" NEW_IP

if [ -f "/home/backIp" ]; then
  OLD_IP=$(cat backIp)
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/mhzx/zdir/android/meta/servers.xml
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/mhzx/zdir/android/meta/version.xml
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/mhzx/zdir/ios/meta/servers.xml
  sed -i "s/${OLD_IP}/${NEW_IP}/g" /home/mhzx/zdir/ios/meta/version.xml
  echo "修改服务端Ip成功,已把IP：${OLD_IP} 修改为 $NEW_IP"
else
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/mhzx/zdir/android/meta/servers.xml
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/mhzx/zdir/android/meta/version.xml
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/mhzx/zdir/ios/meta/servers.xml
  sed -i "s/192.168.2.208/${NEW_IP}/g" /home/mhzx/zdir/ios/meta/version.xml
  echo "${NEW_IP}" >backIp
  echo "修改服务端Ip成功,已把IP：192.168.2.208 修改为 $NEW_IP"
fi
